#!/bin/bash
j=0
while true
do
	dat=`date`
	nc -z  172.16.40.22 21 &>/dev/null  
	if (($? == 0))
	then 
		(($j != 0))&&echo "the ftp service had down $j seconds" 
		echo "$dat the 172.16.40.22 ftp service running" 
		(($j != 0))&&echo "$dat the ftp service had down $j seconds" >>error.log
		j=0
	else
		(($j == 0))&&echo "$dat  the 172.16.40.22 ftp service down" 
		((j++))
	fi
	sleep 1
done
